package com.atguigu;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @ClassName CallableDemo
 * @Author yy
 * @create 2022/9/8 19:27
 */

class MyThread implements Callable{
    @Override
    public Object call() throws Exception {
        System.out.println("----come in Callable 复杂计算");
        return "0526";
    }

}

public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask(()->{
            System.out.println("----come in Callable 复杂计算  1----");
            return "0526  1";
        });
        FutureTask futureTask2 = new FutureTask(()->{
            System.out.println("----come in Callable 复杂计算  2----");
            return "0526  2";
        });

        FutureTask futureTask3 = new FutureTask(new MyThread());


        new Thread(futureTask,"A").start();
        new Thread(futureTask,"A").start();
        new Thread(futureTask2,"B").start();
        new Thread(futureTask3,"C").start();

        System.out.println(Thread.currentThread().getName()+"\t"+"---over");

        System.out.println(futureTask.get());
        System.out.println(futureTask2.get());
        System.out.println(futureTask3.get());




//        FutureTask futureTask = new FutureTask(new MyThread());
//        FutureTask futureTask2 = new FutureTask(new MyThread());

//        FutureTask futureTask = new FutureTask(()->{
//            System.out.println("----come in Callable 复杂计算");
//            return "0526";
//        });
//        FutureTask futureTask2 = new FutureTask(()->{
//            System.out.println("----come in Callable2 复杂计算");
//            return "0526  ---2";
//        });
//
//        for (int i = 1; i <= 2; i++) {
//            new Thread(futureTask,"A").start();
//        }
//
//        new Thread(futureTask,"A").start();
//
//        new Thread(futureTask2,"B").start();
//
//
//        System.out.println(Thread.currentThread().getName()+"\t"+"---over");
//
//        System.out.println(futureTask.get());
//        System.out.println(futureTask.get());
//        System.out.println(futureTask2.get());
    }
}
